home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / misc / gs261src.zip / dict.h < prev    next >
C/C++ Source or Header  |  1993-05-13  |  4KB  |  98 lines

  1. /* Copyright (C) 1989, 1992 Aladdin Enterprises.  All rights reserved.
  2.  
  3. This file is part of Ghostscript.
  4.  
  5. Ghostscript is distributed in the hope that it will be useful, but
  6. WITHOUT ANY WARRANTY.  No author or distributor accepts responsibility
  7. to anyone for the consequences of using it or for whether it serves any
  8. particular purpose or works at all, unless he says so in writing.  Refer
  9. to the Ghostscript General Public License for full details.
  10.  
  11. Everyone is granted permission to copy, modify and redistribute
  12. Ghostscript, but only under the conditions described in the Ghostscript
  13. General Public License.  A copy of this license is supposed to have been
  14. given to you along with Ghostscript so you can know your rights and
  15. responsibilities.  It should be in a file named COPYING.  Among other
  16. things, the copyright notice and this notice must be preserved on all
  17. copies.  */
  18.  
  19. /* dict.h */
  20. /* Interfaces for Ghostscript dictionary package */
  21.  
  22. /*
  23.  * Contrary to our usual practice, we expose the (first-level)
  24.  * representation of a dictionary in the interface file,
  25.  * because it is so important that access checking go fast.
  26.  * The access attributes for the dictionary are stored in
  27.  * the contents ref.
  28.  */
  29. struct dict_s {
  30.     ref count;        /* t_integer, # of occupied entries; */
  31.                 /* "size" is maxlength as seen by client. */
  32.     ref keys;        /* t_shortarray or t_array, keys */
  33.     ref values;        /* t_array, values */
  34. };
  35.  
  36. /* Define the maximum size of a dictionary. */
  37. extern const uint dict_max_size;
  38.  
  39. /* Define whether dictionaries expand automatically when full. */
  40. /* Note that if dict_auto_expand is true, dict_put, dict_copy, and */
  41. /* dict_resize cannot return e_dictfull; however, they can return */
  42. /* e_VMerror.  (dict_lookup and dict_find can return e_dictfull */
  43. /* even if dict_auto_expand is true.) */
  44. extern int dict_auto_expand;
  45.  
  46. /* Create a dictionary. */
  47. extern int dict_create(P2(uint maxlength, ref *pdref));
  48.  
  49. /* Return a pointer to a ref that holds the access attributes */
  50. /* for a dictionary. */
  51. #define dict_access_ref(pdref) (&(pdref)->value.pdict->values)
  52. #define check_dict_read(dref) check_read(*dict_access_ref(&dref))
  53. #define check_dict_write(dref) check_write(*dict_access_ref(&dref))
  54.  
  55. /* Look up in a stack of dictionaries.  Store a pointer to the value slot */
  56. /* where found, or to the (value) slot for inserting. */
  57. /* Return 1 if found, 0 if not and there is room for a new entry, */
  58. /* or e_dictfull if the dictionary is full and the key is missing. */
  59. /* The caller is responsible for ensuring key is not a null. */
  60. /* Note that pdbot <= pdtop, and the search starts at pdtop. */
  61. extern int dict_lookup(P4(const ref *pdbot, const ref *pdtop, const ref *key, ref **ppvalue));
  62. /* Look up in just one dictionary. */
  63. #define dict_find(dref,key,ppvalue) dict_lookup(dref,dref,key,ppvalue)
  64.  
  65. /* Enter a key-value pair in a dictionary. */
  66. /* Return 0, e_dictfull, or e_VMerror if the key was a string */
  67. /* and a VMerror occurred when converting it to a name. */
  68. extern int dict_put(P3(ref *pdref, const ref *key, const ref *pvalue));
  69.  
  70. /* Remove a key-value pair from a dictionary. */
  71. /* Return 0 or e_undefined. */
  72. extern int dict_undef(P2(ref *pdref, const ref *key));
  73.  
  74. /* Return the number of elements in a dictionary. */
  75. extern uint dict_length(P1(const ref *pdref));
  76.  
  77. /* Return the capacity of a dictionary. */
  78. extern uint dict_maxlength(P1(const ref *pdref));
  79.  
  80. /* Copy one dictionary into another. */
  81. /* Return 0 or e_dictfull. */
  82. extern int dict_copy(P2(const ref *dfrom, ref *dto));
  83.  
  84. /* Grow or shrink a dictionary. */
  85. /* Return 0, e_dictfull, or e_VMerror. */
  86. extern int dict_resize(P2(ref *pdref, uint newmaxlength));
  87.  
  88. /* Prepare to enumerate a dictionary. */
  89. /* Return an integer suitable for the first call to dict_next. */
  90. extern int dict_first(P1(const ref *pdref));
  91.  
  92. /* Enumerate the next element of a dictionary. */
  93. /* index is initially the result of a call on dict_first. */
  94. /* Either store a key and value at eltp[0] and eltp[1] */
  95. /* and return an updated index, or return -1 */
  96. /* to signal that there are no more elements in the dictionary. */
  97. extern int dict_next(P3(const ref *pdref, int index, ref *eltp));
  98.